/-app
/-docs ...
/-docs/types ...
text.ts
api.ts
/-files
/-imports
/-storage
/-typings
codemirror.d.ts
knockout.d.ts
websql.d.ts
errors.js
functions.ts
index.html
try.js
x
    editorCache.push(editor);
 
1
module teapo.docs.types.text {
2
  
3
  export function load(fullPath: string, read: (property: string) => string, write: (property: string, content: string) => void): DocumentHandler {
4
    
5
    return null;
6
    
7
  }
8
  
9
  export class TextDocumentHandler implements DocumentHandler {
10
​
11
    private _doc: CodeMirror.Doc = null;
12
    private _text: string = null;
13
    private _editor: { cm: CodeMirror; host: HTMLElement; } = null;
14
​
15
    constructor(
16
      private _read: (property: string) => string,
17
      private _write: (property: string, content: string) => void) {
18
      
19
    }
20
    
21
    getText() {
22
      if (this._text === null) {
23
        if (this._doc)
24
          this._text = this._doc.getValue();
25
        else
26
          this._text = this._read(null);
27
      }
28
      return this._text;
29
    }
30
    
31
    getDoc() {
32
      if (!this._doc) {
33
        this._doc = new CodeMirror.Doc(this.getText());
34
        // TODO: process history and/or cusor/scroll position
35
      }
36
      return this._doc;
37
    }
38
    
39
    
40
​
41
    open(): HTMLElement {
42
​
43
      return this._getEditor().host;
44
      
45
    }
46
​
47
    close() {
48
      if (this._editor) {
49
        var e = this._editor;
50
        this._editor = null;
51
        returnEditor(e);
52
      }
53
    }
54
​
55
    private _getEditor() {
76:29